package eerr.llrr.oorr.pte9983.uggtip9324

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import eerr.llrr.oorr.pte9983.wifi4392.jump98001.RouteJump

class BatteryUtils : BroadcastReceiver() {

    companion object {
        const val BATTERY_CONNECT: Int = 1
        const val BATTERY_DISCONNECT = 2
        const val BATTERY_CHANGE = 3
        const val BATTERY_OKAY = 4

        fun register(context: Context?) {
            try {
                var batteryUt = BatteryUtils()
                val filter = IntentFilter()
                filter.addAction(Intent.ACTION_POWER_CONNECTED)
                filter.addAction(Intent.ACTION_POWER_DISCONNECTED)
                filter.addAction(Intent.ACTION_BATTERY_CHANGED)
                filter.addAction(Intent.ACTION_BATTERY_OKAY)
                filter.priority = IntentFilter.SYSTEM_HIGH_PRIORITY

                context?.registerReceiver(batteryUt, filter)

            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }


    override fun onReceive(context: Context?, intent: Intent?) {

        when (intent?.action) {
            Intent.ACTION_POWER_CONNECTED -> {
                RouteJump.safeJump(yyee.llee.mmee.pl190.host668.RouteKey.BATTERY_CONNECT)
                yyee.llee.mmee.pl190.host668.LiveDataBus.get().register(
                    yyee.llee.mmee.pl190.host668.BusKey.BATTERY_STATUS, Int::class.java
                ).value = BATTERY_CONNECT

            }

            Intent.ACTION_POWER_DISCONNECTED -> {
                RouteJump.safeJump(yyee.llee.mmee.pl190.host668.RouteKey.BATTERY_DISCONNECT)
                yyee.llee.mmee.pl190.host668.LiveDataBus.get().register(
                    yyee.llee.mmee.pl190.host668.BusKey.BATTERY_STATUS, Int::class.java
                ).value = BATTERY_DISCONNECT

            }

            Intent.ACTION_BATTERY_CHANGED -> {

            }

            Intent.ACTION_BATTERY_OKAY -> {

                yyee.llee.mmee.pl190.host668.LiveDataBus.get().register(
                    yyee.llee.mmee.pl190.host668.BusKey.BATTERY_STATUS, Int::class.java
                ).value = BATTERY_OKAY

            }
        }


    }


}